﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
namespace CTEA_INDIA
{
    public partial class ListOfenquiry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (Session["UserID"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            if (!IsPostBack)
            {
                string Location = Session["Location"].ToString();
                ViewState["Location"] = Location;
                PopulateEnquiry(0, Location);
            
            }
        }
      
        public void PopulateEnquiry(int type, string Location)
        {
            
            DataSet ds = BAL.Customers.GetEnquies(type,Location);
            if (type==1)
            {
                spnMsg.InnerHtml = "List of Pending Enquries.";
                
                gvEnquiry.Columns[5].Visible = false;
                gvEnquiry.Columns[6].Visible = true;
                gvEnquiry.Columns[7].Visible = true ;
                gvEnquiry.Columns[8].Visible = false;

              
            }
                            else

                if (type == 0)
                {
                    spnMsg.InnerHtml = "List of Unsolved Enquries.";
                    gvEnquiry.Columns[5].Visible = true;
                    gvEnquiry.Columns[6].Visible = false  ;
                    gvEnquiry.Columns[7].Visible = false;
                    gvEnquiry.Columns[8].Visible = true;
                }
                else
                {
                    spnMsg.InnerHtml = "List of Success Enquires";
                    gvEnquiry.Columns[5].Visible = false;
                    gvEnquiry.Columns[6].Visible = false ;
                    gvEnquiry.Columns[7].Visible = false;
                    gvEnquiry.Columns[8].Visible = false;
                }  gvEnquiry.DataSource = ds;
                    gvEnquiry.DataBind();
                   
        }

        protected void gdCandidateProfile_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Button SubmitButton = (Button)e.Row.FindControl("btnSubmit");

            }
        }

        protected void btnSchedule_Click(object sender, EventArgs e)
        {
            Button btnsc= (Button)sender;
            GridViewRow row = (GridViewRow)btnsc.Parent.Parent;

        
            int Eid = Convert.ToInt32(gvEnquiry.DataKeys[row.RowIndex]["EnquiryID"]);
    lblEnquiryId.Text = Convert.ToString( Eid);
          //  ModalPopupExtender1.TargetControlID = "btnsc";
            ModalPopupExtender1.Show();
        }

        protected void btnSucess_Click(object sender, EventArgs e)
        {
             Button btnsc= (Button)sender;
            GridViewRow row = (GridViewRow)btnsc.Parent.Parent;
            int Eid = Convert.ToInt32(gvEnquiry.DataKeys[row.RowIndex]["EnquiryID"]);
          //int EnquiryID = Convert.ToInt32( row.Cells[0].Text );

          BAL.Customers.UpdtChangetoSuccess(Eid, 2);




          PopulateEnquiry(1, Session["Location"].ToString());
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DateTime SchdeuleDate = Convert.ToDateTime( txtScheule.Text);
            int EnquiryID =Convert.ToInt32( lblEnquiryId.Text);
            
            BAL.Customers.UpdateEnquiry(SchdeuleDate, EnquiryID,1);
            PopulateEnquiry(0, Session["Location"].ToString());
        }

        protected void btnTodaySchedule_Click(object sender, EventArgs e)
        {
            DataSet ds = BAL.Customers.GetEnquies(3, Session["Location"].ToString());
           
                    spnMsg.InnerHtml = "List of Today's Schdeul";
                    gvEnquiry.Columns[5].Visible = false;
                    gvEnquiry.Columns[6].Visible = true;
                    gvEnquiry.Columns[7].Visible = false;
                    gvEnquiry.Columns[8].Visible = false;
                gvEnquiry.DataSource = ds;
            gvEnquiry.DataBind();

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Button btnsc = (Button)sender;
            GridViewRow row = (GridViewRow)btnsc.Parent.Parent;
            int Eid = Convert.ToInt32(gvEnquiry.DataKeys[row.RowIndex]["EnquiryID"]);
            lblEnqID.Text = Convert.ToString(Eid);
            ModalPopupExtender2.Show();
        }

        protected void lnkPending_Click(object sender, EventArgs e)
        {
            PopulateEnquiry(1, Session["Location"].ToString());
        }

        protected void lnkSolved_Click(object sender, EventArgs e)
        {
            PopulateEnquiry(2, Session["Location"].ToString());
           
        
        }

        protected void lnkUnsolved_Click(object sender, EventArgs e)
        {
            PopulateEnquiry(0, Session["Location"].ToString());
        }

        protected void lnkEnquiry_Click(object sender, EventArgs e)
        {
            LinkButton lnkEnquiry = (LinkButton)sender;
        }

        protected void ModalPopupExtender2_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BAL.Customers.PopulateLocation(ref ddlLocation1);
            }

        }

        protected void btntransfer_Click(object sender, EventArgs e)
        {
            
            string AssingLoc = ddlLocation1.SelectedValue;
            int Eid = Convert.ToInt32(lblEnqID.Text);
            BAL.Customers.updateAssgnLoc(AssingLoc, Eid);
            PopulateEnquiry(0, Session["Location"].ToString());
        }
      
    }
}